
export default class DataProxy
{
    constructor(obj)
    {
        this.objArray = [];

        if (Array.isArray(obj)) {
            obj.forEach((o)=>{
                if (o !== undefined) {
                    this.defineProperty(o);
                }
            });
        }
        else {
            this.defineProperty(obj);
        }
    }

    defineProperty(obj) {
        this.objArray.push(obj);

        let self = this;
        Object.keys(obj).forEach((key) => {
            Object.defineProperty(this, key, {
                enumerable: true,
                configurable: true,
                get: function () {
                    return self._getProperty(key);
                }
            });
        });
    }

    _getProperty(key) {
        for (let i = 0; i < this.objArray.length; ++i) {
            if (key in this.objArray[i]) {
                return this.objArray[i][key];
            }
        }
        return undefined;
    }
}